<template>
  <view class="account-safe">
    <u-cell-group>
      <u-cell-item
        icon="account"
        :title="$t('修改密码')"
        @click="navigateTo('../setPassword/setPassword')"
      ></u-cell-item>
      <u-cell-item
        icon="lock"
        :title="$t('安全认证')"
        @click="navigateTo('../safetyCertification/safetyCertification')"
      ></u-cell-item>
      <u-cell-item
        icon="trash"
        :title="$t('账户注销')"
        @click="navigateTo('../accountCancellation/accountCancellation')"
      ></u-cell-item>
    </u-cell-group>
  </view>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'

export default {
  data() {
    return {}
  },
  computed: {
    ...mapGetters(['userInfo', 'api'])
  },
  onLoad() {
    uni.setNavigationBarTitle({title: this.$t('账号与安全')})
  },
  methods: {
    ...mapActions(['remove_logout']),
    //账号注销
    accountCancellation() {
      uni.showModal({
        title: '提示',
        content: '确认账号注销？',
        success: (res) => {
          if (res.confirm) {
            this.$u.post(this.api.GLOBAL_auth_user_cancel, {}).then((res) => {
              if (res.code === 200) {
                //用户退出
                this.remove_logout()
                uni.reLaunch({
                  url: '../template/login/login'
                })
                setTimeout(() => {
                  uni.showToast({
                    title: '注销成功'
                  })
                }, 2000)
              }
            })
          } else if (res.cancel) {
          }
        }
      })
    },
    navigateTo(url) {
      uni.navigateTo({ url })
    }
  }
}
</script>

<style lang="scss"></style>
